package com.leetcode.contest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author `RKC`
 * @date 2021/11/10 20:30
 */
public class LC2032至少在两个数组中出现的值 {

    public static List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
        List<Integer> answer = new ArrayList<>();
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        Arrays.sort(nums3);
        int[] cnt = new int[101];
        for (int i = 0; i < nums1.length; i++) {
            if (i >= 1 && nums1[i] == nums1[i - 1]) continue;
            cnt[nums1[i]]++;
        }
        for (int i = 0; i < nums2.length; i++) {
            if (i >= 1 && nums2[i] == nums2[i - 1]) continue;
            cnt[nums2[i]]++;
        }
        for (int i = 0; i < nums3.length; i++) {
            if (i >= 1 && nums3[i] == nums3[i - 1]) continue;
            cnt[nums3[i]]++;
        }

        for (int i = 1; i <= 100; i++) {
            if (cnt[i] >= 2) {
                answer.add(i);
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        int[] nums1 = {1, 1, 3, 2}, nums2 = {2, 3}, nums3 = {3};
        System.out.println(twoOutOfThree(nums1, nums2, nums3));
    }
}
